<?php
/*
Template Name: Google Custom Search Results
*/
?>
<?php get_header(); ?>
<div id="postlist">
	<?php if(have_posts()): ?>
			<?php while(have_posts()):the_post(); ?>
				<div class="post">
						<div class="clear"></div>
						<div class="entry">
						<div id="cse" style="width: 100%;">Loading</div>
						<script src="http://www.google.com/jsapi" type="text/javascript"></script>
						<script type="text/javascript"> 
						  google.load('search', '1', {language : 'zh-CN', style : google.loader.themes.V2_DEFAULT});
						  google.setOnLoadCallback(function() {
						    var customSearchOptions = {};  var customSearchControl = new google.search.CustomSearchControl(
						      '015332604376988026510:0q91fi6ihrc', customSearchOptions);
						    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
						    customSearchControl.draw('cse');
						    function parseParamsFromUrl() {
						      var params = {};
						      var parts = window.location.search.substr(1).split('\x26');
						      for (var i = 0; i < parts.length; i++) {
						        var keyValuePair = parts[i].split('=');
						        var key = decodeURIComponent(keyValuePair[0]);
						        params[key] = keyValuePair[1] ?
						            decodeURIComponent(keyValuePair[1].replace(/\+/g, ' ')) :
						            keyValuePair[1];
						      }
						      return params;
						    }

						    var urlParams = parseParamsFromUrl();
						    var queryParamName = "q";
						    if (urlParams[queryParamName]) {
						      customSearchControl.execute(urlParams[queryParamName]);
						    }
						  }, true);
						</script>
						</div>
				</div>
				<div class="comfrm">
					<div class="comcon">
					<?php comments_template( '', true ); ?>
					<br/>
					</div>
				</div>
			<?php endwhile; ?>
	<?php else: ?>
			<div class="post">
				<h2><?php _e('sorry not found','may701'); ?></h2>
			</div>
	<?php endif; ?>	
</div>
<?php get_footer(); ?>